package cn.itcast.nems.studentrecord.web.controller.b;

import cn.itcast.ic.common.bean.Page;
import cn.itcast.nems.common.PageQueryModel;
import cn.itcast.nems.common.web.vo.BasePageRequest;
import cn.itcast.nems.journal.dto.JournalRenewalLineDTO;
import cn.itcast.nems.journal.service.JournalRenewalLineService;
import cn.itcast.nems.manager.util.CustomBeanUtil;
import cn.itcast.nems.studentrecord.web.vo.query.JournalRenewalLinePageQueryVO;
import com.alibaba.fastjson.JSON;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 升级凭单行
 * </p>
 *
 * @author zhouwei
 * @since 2023/11/16 4:14 PM
 **/
@RestController
@RequestMapping("/b/renewal")
@RequiredArgsConstructor
@Slf4j
public class JournalRenewalLineController {
    private final JournalRenewalLineService journalRenewalLineService;

    /**
     * 升级凭单行- 学员分页查询
     *
     * @param renewalId  升级凭单头ID
     * @param queryParam 参数参数
     * @return 分页数据
     **/
    @PostMapping("/{renewal_id}/lines")
    public ResponseEntity<Page<JournalRenewalLineDTO>> findPageListByRenewalId(@PathVariable("renewal_id") String renewalId,
                                                                               @RequestBody BasePageRequest<JournalRenewalLinePageQueryVO> queryParam) {
        log.info("【升级凭单学生分页查询】请求参数 renewalId：{}, queryParam：{}", renewalId, JSON.toJSONString(queryParam));
        queryParam.convert();
        JournalRenewalLinePageQueryVO condition = queryParam.getCondition();
        JournalRenewalLineDTO lineDTO = CustomBeanUtil.copyProperties(condition, new JournalRenewalLineDTO());
        lineDTO.setJournalRenewalId(renewalId);
        PageQueryModel<JournalRenewalLineDTO> queryModel = new PageQueryModel<>(queryParam.getPageNumber(), queryParam.getPageSize(), lineDTO);
        return ResponseEntity.ok().body(journalRenewalLineService.findPageListByRenewalId(queryModel, condition.getApprovalType()));
    }
}
